package com.eshop.modules.monitor.rest;

import org.springframework.web.bind.annotation.GetMapping;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.http.HttpStatus;
import com.eshop.utils.RequestHolder;
import org.springframework.http.ResponseEntity;
import com.eshop.modules.monitor.service.VisitsService;
import io.swagger.annotations.Api;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping({ "/api/visits" })
@Api(tags = { "系统:访问记录管理" })
public class VisitsController
{
    private final VisitsService visitsService;
    
    public VisitsController(final VisitsService visitsService) {
        this.visitsService = visitsService;
    }
    
    @PostMapping
    @ApiOperation("创建访问记录")
    public ResponseEntity<Object> create() {
        this.visitsService.count(RequestHolder.getHttpServletRequest());
        return new ResponseEntity(HttpStatus.CREATED);
    }
    
    @GetMapping
    @ApiOperation("查询")
    public ResponseEntity<Object> get() {
        return new ResponseEntity(this.visitsService.get(), HttpStatus.OK);
    }
    
    @GetMapping({ "/chartData" })
    @ApiOperation("查询图表数据")
    public ResponseEntity<Object> getChartData() {
        return new ResponseEntity(this.visitsService.getChartData(), HttpStatus.OK);
    }
}
